package graphicUserInterface.elements;

import java.awt.Color;

import javax.swing.JFrame;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;

public class HINBRect extends JLayeredPane {
	/**
	 * 
	 */
	private static final long serialVersionUID = 4991233342732963030L;
	/* *********************************************************
	 * Attributes
	 * ********************************************************* */
	private JPanel _north;
	private JPanel _south;
	private JPanel _east;
	private JPanel _west;
	private Color _color;
	
	/* *********************************************************
	 * Constructor(s)
	 * ********************************************************* */
	public HINBRect(int width, int height, int border, Color col){
		_color = col;
		_north = new JPanel();
		this.add(_north);
		_south = new JPanel();
		this.add(_south);
		_west = new JPanel();
		this.add(_west);
		_east = new JPanel();
		this.add(_east);
		this.validateColor();
		this.initBorder(width,height,border);
		this.validate();
	}

	
	
	/* *********************************************************
	 * Instance Methods
	 * ********************************************************* */
	private void validateColor() {
		_north.setBackground(_color);
		_south.setBackground(_color);
		_west.setBackground(_color);
		_east.setBackground(_color);
	}



	private void initBorder(int width, int height, int border) {
		_north.setSize(width, border);
		
		_west.setSize(border, height);
		
		_east.setSize(border, height);
		_east.setLocation(width-border, 0);
		
		_south.setSize(width, border);
		_south.setLocation(0, height-border);
	}
	
	public void setParams(int width, int height, int border, Color col){
		_color = col;
		validateColor();
		initBorder(width, height, border);
		this.validate();
	}
	
	/* *********************************************************
	 * Tests
	 * But Prefer writing a TestFile in the Test Package
	 * ********************************************************* */
	public static void main(String[] args) {
		JFrame test = new JFrame();
		test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		System.out.println(test.getLayout());
		JPanel panel = new JPanel();
		panel.setSize(640,480);
		panel.setBackground(Color.BLUE);
		test.add(panel);
		test.add(new HINBRect(600, 400, 50, Color.RED));
		test.setVisible(true);
	}
}
